﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using Common.DataTypes;
using System.Xml;
using System.IO;
using Common;
using System.Xml.Serialization;

namespace LINQAmazonProvider
{
    public static class ResultXMLParser
    {
        //public string XmlToParse { get; set; }

        //public ResultXMLParser(string xml) {
        //    this.XmlToParse = xml;
        //}

        public static List<Item> Parse(string serializedObj)
        {
            AmazonBookCollection ABookCollection = null;
            try
            {
                XmlReader xmlReader = XmlReader.Create(new StringReader(serializedObj));

                XmlSerializer xSerializer = new XmlSerializer(typeof(AmazonBookCollection));

                ABookCollection = (AmazonBookCollection)xSerializer.Deserialize(xmlReader);
            }
            catch (Exception e) { 
            }

            return (ABookCollection.ObtenerBooks());
        }
    }
}
